SRCDIR :=.
OBJDIR := obj
MAIN := ./Main.cpp
SRCS := $(filter-out $(MAIN) $(SRCDIR)/Gem5Wrapper.cpp, $(wildcard $(SRCDIR)/*.cpp))
OBJS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRCS))

CACHE_SRC_DIR:= ./cache
CACHE_SRCS=$(wildcard $(CACHE_SRC_DIR)/*.cpp)
CACHE_OBJS :=$(patsubst %.cpp, %.o, $(CACHE_SRCS)) 

# Ramulator currently supports g++ 5.1+ or clang++ 3.4+.  It will NOT work with
#   g++ 4.x due to an internal compiler error when processing lambda functions.
CXX := g++
# CXX := g++-5
CXXFLAGS := -O0 -std=c++11 -g -Wall

.PHONY: all clean depend

all: depend spmv

clean:
	rm -f spmv
	rm -rf $(OBJDIR)

depend: $(OBJDIR)/.depend


$(OBJDIR)/.depend: $(SRCS)
	@mkdir -p $(OBJDIR)
	@rm -f $(OBJDIR)/.depend
	@$(foreach SRC, $(SRCS), $(CXX) $(CXXFLAGS) -DRAMULATOR -MM -MT $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRC)) $(SRC) >> $(OBJDIR)/.depend ;)

ifneq ($(MAKECMDGOALS),clean)
-include $(OBJDIR)/.depend
endif

print: 
	@echo $(SRCS) 

spmv: $(MAIN) $(OBJS) $(SRCDIR)/*.h
	$(CXX) $(CXXFLAGS) -o $@ $(MAIN) $(OBJS) 

core.o:core.cpp
	$(CXX) $(CXXFLAGS)  -c -o $@ $<

libramulator.a: $(OBJS)
	libtool -static -o $@ $(OBJS)

$(OBJS): | $(OBJDIR)

$(OBJDIR): 
	@mkdir -p $@

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

